package com.hdl.sqlSession;

import com.hdl.config.XmlConfigBuilder;
import com.hdl.pojo.Configuration;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * @author hedonglin
 * @date 2020/4/21 21:03
 * @description sqlSessionFactory构建器
 */
public class SqlSessionFactoryBuilder {

    public SqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException, ClassNotFoundException {
        // 1、使用dom4j解析配置文件，讲解析出来的内容封装到Configuration中
        XmlConfigBuilder xmlConfigBuilder = new XmlConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        // 创建SqlSessionFactory类， 工厂类：生产SqlSession：会话对象
        return new DefaultSqlSessionFactory(configuration);
    }
}
